<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="/js/vue-2.7.9-dev.js"></script>
    <title>收集表单数据</title>
</head>
<body>
    <div id="app">
        <form @submit.prevent="demo">
          账号：<input type="text" v-model.lazy.trim="userInfo.account"> <br /><br />
          <div>{{userInfo.account}}</div>
          密码：<input type="password" v-model="userInfo.password"> <br /><br />
          年龄：<input type="number" v-model.number="userInfo.age"> <br /><br />
          性别：
          男<input type="radio" name="sex" v-model="userInfo.sex" value="male">
          女<input type="radio" name="sex" v-model="userInfo.sex" value="female"> <br /><br />
          爱好：
          学习<input type="checkbox" v-model="userInfo.hobby" value="study">
          打游戏<input type="checkbox" v-model="userInfo.hobby" value="game">
          吃饭<input type="checkbox" v-model="userInfo.hobby" value="eat">
          <br /><br />
          地址
          <select v-model="userInfo.city">
            <option value="">请选择地址</option>
            <option value="beijing">北京</option>
            <option value="shanghai">上海</option>
            <option value="shenzhen">深圳</option>
            <option value="guangzhou">广州</option>
          </select>
          <br/><br/>
          其他信息：
          <textarea v-model.lazy="userInfo.other"></textarea> <br/><br/>
          <input type="checkbox" v-model="userInfo.agree">阅读并接受
          <a href="https://www.yuque.com/cessstudy">《用户协议》</a>
          <button>提交</button>
        </form>
      </div>
    <script>
        let vm = new Vue({
            data() { 
                console.log("==", this);
                return { 
                    userInfo: {
                        account: '',
                        password: '',
                        age: "18",
                        sex: 'female',
                        hobby: [],
                        city: 'beijing',
                        other: '',
                        agree: ''
                    }
                }
            },
            methods: {
                demo() {
                    console.log(JSON.stringify(this.userInfo))
                }
            }
        })
        vm.$mount("#app")
        console.log("--",vm);
    </script>
</body>
</html>